package com.jinke.uang.ui;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.WindowManager;

import com.jinke.uang.R;
import com.jinke.uang.base.BaseNetActivity;
import com.jinke.uang.cache.Acache;
import com.jinke.uang.main.MainActivity;
import com.jinke.uang.utils.StringUtils;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 闪屏页
 */
public class WelcomeActivity extends BaseNetActivity {

    @Override
    protected void initViews() {}

    @Override
    protected void onUIReady() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
                .LayoutParams.FLAG_FULLSCREEN);// 全屏显示
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);


        jumpToLogin();
    }

    private void jumpToLogin() {
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                String  main=Acache.get(getApplication()).getAsString("main");
                if(StringUtils.isNotBlank(main)&&"1".equals(main)){
                    Intent mainIntent = new Intent(WelcomeActivity.this, MainActivity.class);
                    startActivity(mainIntent);
                }else{
                    Intent mainIntent = new Intent(WelcomeActivity.this, MainCaActivity.class);
                    startActivity(mainIntent);
                }

//                overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
                finish();
            }
        };
        timer.schedule(timerTask, 1500);
    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_splash;
    }

    @Override
    public String getPageTitle() {
        return null;
    }

    @Override
    protected int getResId() {
        return 0;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
